<template>
  <p>{{ num }}</p>
</template>

<script lang="ts">
  import { defineComponent } from 'vue';

  export default defineComponent({
    name: 'PromiseNumber',
    setup: () => {
      return new Promise<{ num: number }>((resolve, reject) => {
        setTimeout(() => {
          const n = Math.random();
          if (n > 0.5) {
            return resolve({ num: n });
          } else {
            reject(new Error('异步请求出错'));
          }
        }, 2000);
      });
    }
  });
</script>

<style scoped></style>
